jsMath

Problem minimuma

""" Lucija Ersek, Ivana Pavlek """ 
       
#funkcija jedne varijable 
       
f = lambda x: x*cos(x) 
       
type(f) 
       
<type 'function'>
plot(f,1,5) 
       
find_minimum_on_interval(f, 1, 5) 
       
(-3.2883713955908962, 3.425618469566611)
#problem: moramo paziti koja je koordinata x, a koja y 
       
plot(f,1,20) 
       
find_minimum_on_interval(f, 1, 20) #problem: na prevelikom intervalu javlja "srednji" minimum 
       
(-9.4772942594797804, 9.5293344598683429)
find_minimum_on_interval(f, 8, 20) 
       
(-15.739676962133709, 15.771284820967489)
x,y = var('x y') 
       
g = sin(x*y) 
       
plot3d(lambda x, y: sin(x*y),(-2,2), (-2,2)) 
       
You do not have the
Java Runtime Environment
installed for applet support.
Visit www.java.com
Get Image
minimize(g,[-2,2]) 
       
Optimization terminated successfully.
         Current function value: -1.000000
         Iterations: 6
         Function evaluations: 8
         Gradient evaluations: 8
(-1.25331247133, 1.25331247133)
minimize(g,[-2,2], disp=0) 
       
(-1.25331247133, 1.25331247133)
minimize(g,[-2,2], disp=0,algorithm="ncg") 
       
(-1.25331413734, 1.25331413734)
vars=var('x y z') 
       
h=100*(y-x^2)^2+(1-x)^2+100*(z-y^2)^2+(1-y)^2 
       
minimize(h,[0,1,2],disp=0) 
       
(0.999999982858, 0.999999988285, 0.999999971261)
minimize_constrained(g, [(None,None),(None,None)],[-2,2]) 
       
(-1.25331419334, 1.25331419334)
minimize_constrained(g, [(-1,1),(-1,1)],[-2,2]) 
       
(-1.0, 1.0)